﻿@model Lari.Services.ViewModel.DepartmentListModel
@using System.Globalization
@using System.Web.Mvc.Html
@using Lari.Configuration
@{
	var grid = new WebGrid(Model.List, rowsPerPage: ApplicationConfig.RowPerPage,
	canPage: true, canSort: true, defaultSort: "Name");
	grid.Pager(WebGridPagerModes.Numeric);
   
}
@functions
{
	MvcHtmlString FormatData(int count, int depid)
	{

		if (count > 0)
		{
		   var a =  Html.ActionLink("Delete", ActionConst.Masters.Common.DepDesignationDelete, new { id = depid },new {@class="deslinktoDelete"}).ToString();
		   a = a + "<div class=\"numberCircle\">" + count.ToString(CultureInfo.InvariantCulture) + "</div>";
			return new MvcHtmlString(a);
		}
		return new MvcHtmlString("");
		
	}

}
<div id="pagetitle">
	<h1>@ScreenName.Masters.Departments</h1>
</div>
<div class="spacer">
</div>
<div id="pagecontent">
	<div class="spacer">
	</div>
	<div id="grid" style="width: 60%; float: left;">
		@grid.GetHtml(
			tableStyle: "webgrid",
			headerStyle: "webgrid-header",
			footerStyle: "webgrid-footer",
			alternatingRowStyle: "webgrid-alternating-row",
			selectedRowStyle: "webgrid-selected-row",
			rowStyle: "webgrid-row-style",
			columns: grid.Columns(grid.Column("Name", "Departments"),
					  grid.Column(format: @<text><a href="#" onclick="Edit('@item.Id','@item.Name',this)">@GuiActionName.Update</a></text>),
					  grid.Column(format: item => Html.ActionLink("Designation", "DepDesignation", new { id = item.Id }, new { @class = "popupClick", data_dialog_id = "popUpDialog", data_dialog_title = "Designation Mapping" })),
					  grid.Column("Designation", canSort: false, format: item => @FormatData(item.DesignationCount, item.Id)),
					  grid.Column(format: item => Html.ActionLink("Specialization", "Specialization", new { id = item.Id }, new { @class = "popupClick", data_dialog_id = "popUpDialog", data_dialog_title = "Specialization Mapping" }))




				)


		   )
	</div>
	@* //grid.Column(format: @<text><a href="#" onclick="OpenModal('@item.Id',this)">Designation</a></text>)*@
	<div style="width: 35%; float: right;">
		<div id="edit" style="border: 0px solid red">
			@using (Html.BeginForm(ActionConst.Masters.Common.DepartmentsModify, ControllerConst.Masters.CoreMaster))
			{
				@Html.AntiForgeryToken("modify title")
				<div>
					<label class="required">
						Department</label>&nbsp;&nbsp;<strong style="font-size: 10px; font-weight: bold"> (Edit)</strong>
					@Html.HiddenFor(m => m.Edit.Id, new { id = "editId" })
				</div>
				<div>
					@Html.TextBoxFor(m => m.Edit.Name, new { id = "editName" })
					@Html.ValidationMessageFor(m => m.Edit.Name)
				</div>
				<div class="doubleSpacer">
				</div>
				<div>
					<input type="submit" value="@GuiActionName.Modify" id="btnModify" />
				</div>
			}
		</div>
		<div id="insert" style="border: 0px solid red">
			@using (Html.BeginForm(ActionConst.Masters.Common.DepartmentsCreate, ControllerConst.Masters.CoreMaster))
			{
				@Html.AntiForgeryToken("New title")
				<div>
					<label class="required">
						Department</label>&nbsp;&nbsp;<strong style="font-size: 10px; font-weight: bold"> (New)</strong>
				</div>
				<div>
					@Html.TextBoxFor(m => m.Insert.Name, new { id = "insertName" })
					@Html.ValidationMessageFor(m => m.Insert.Name)
				</div>
				<div class="doubleSpacer">
				</div>
				<div>
					<input type="submit" value="@GuiActionName.Save" id="btnSubmit" />
				</div>
			}
		</div>
	</div>
	<div class="clear">
	</div>
	<div class="doubleSpacer">
	</div>
	<div>
		<a href="#" id="hrefInsert">@ScreenName.Masters.CreateDepartment</a>
	</div>
	<div class="spacer">
	</div>
</div>
<div id="modal_dialog" style="background: none repeat scroll 0 0 #EEEEEE">Do you want to delete designation mapping for this department ?</div>
<script type="text/javascript">
	
	var previousRow;
	var previousClass;
	var deleteLinkUrl;
	
	function Edit(id, name,obj) 
	{
		$("#edit").show();
		$("#insert").hide();
		$("#editId").val(id);
		$("#editName").val(name);
		if(previousRow!=null && previousClass!=null) 
		{
			previousRow.setAttribute('class', previousClass);
		}

		previousRow = obj.parentNode.parentNode;
		previousClass = obj.parentNode.parentNode.className;
		
		obj.parentNode.parentNode.setAttribute('class', 'webgrid-selected-row '+previousClass);
		return false;
		
	}
	
   
	$(document).ready(function () 
		{
			$.ajaxSetup({ cache: false });
		
			@if (Model.Edit == null)
			{
				<text> $("#edit").hide();</text>
			}
			@if (Model.Insert == null)
			{
				<text> $("#insert").hide();</text>
			}
		
			$("#btnSubmit").button();
			$("#btnModify").button();
		
			$("#hrefInsert").click(function() {
				$("#edit").hide();
				$("#insert").show();
			});
		
			$(".popupClick").live("click", function (e) {
				e.preventDefault();
				$("<div></div>")
					.addClass("dialog")
					.css("background","none repeat scroll 0 0 #EEEEEE")
					.attr("id", $(this)
					.attr("data-dialog-id"))
					.appendTo("body")
					.dialog({
						title: $(this).attr("data-dialog-title"),
						close: function () { $(this).remove(); window.location.reload(true);},
						modal: true,
						resizable:false,
						width:600, height:500
						
					})
					.load(this.href);

				
				
			});

		$(".deslinktoDelete").live("click", function(e) {
			e.preventDefault();
			deleteLinkUrl = this.href;
			$("#modal_dialog").dialog('open');
			//alert(deleteLinkUrl);
			
		
		});
		
		 $("#modal_dialog").dialog({
					resizable: false,
					height:140,
					width:400,
					modal: true,
					autoOpen:false,
					title: 'Delete Confirmation',
					buttons: {
						"Yes": function() {
							$( this ).dialog( "close" );
							window.location = deleteLinkUrl;
						},
						"No": function() {
							$( this ).dialog( "close" );
						   
						}
					}
			  });
		
//            $("#modal_dialog").dialog({ width: 600, resizable: true, position: 'center', title: 'Map Designations', autoOpen: false, modal:true,
//                            
//                                close:function(){$(this).dialog( "close" ) ;}
//                    });
		
		 });
  
</script>
